package com.yuanfeng.activity.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.activity.entity.ActivityShareGetRedpacketGradeEntity;
import com.yuanfeng.activity.mapper.ActivityShareGetRedpacketGradeMapper;
import com.yuanfeng.activity.service.ActivityShareGetRedpacketGradeService;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseTokenUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.vo.user.UserInfoVO;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *
 */
@Service
public class ActivityShareGetRedpacketGradeServiceImpl extends ServiceImpl<ActivityShareGetRedpacketGradeMapper, ActivityShareGetRedpacketGradeEntity>
    implements ActivityShareGetRedpacketGradeService{

    @Override
    public ResponseResult updateShareGetRpGrade(Map<String, Object> param) {
        UserInfoVO userInfo = ParseTokenUtils.getPlatformUser(param.get("token").toString());
        if (null != userInfo) {
            String userRealname = userInfo.getUserRealname();
            if (null == userRealname) {
                userRealname = userInfo.getUserId();
            }
            param.put("gradeUpdateBy",userRealname);
        }
        param.put("updateDate",new Date());
        if (null == param.get("prizeId")) {
            this.baseMapper.insertShareGetRpGrade(param);
        } else {
            this.baseMapper.updateShareGetRpGrade(param);
        }

        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
    }

    @Override
    public ResponseResult deleteShareGetRpGrade(Map<String, Object> param) {
        this.baseMapper.deleteById(param.get("gradeId").toString());

        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL);
    }

    @Override
    public ResponseResult queryShareGetRpGrade(Map<String, Object> param) {
        List<ActivityShareGetRedpacketGradeEntity> list=this.baseMapper.selectList(new LambdaQueryWrapper<ActivityShareGetRedpacketGradeEntity>()
                                                        .eq(ActivityShareGetRedpacketGradeEntity::getRuleId,Integer.valueOf(param.get("ruleId").toString())));
        return ResponseResult.success(list);
    }
}




